import type {
  AddCartDataParams,
  AddCartResult,
  CreateOrderDataParams,
  GetNowOrderDataParams,
  GetNowOrderResult,
  GetOrderDetailResult,
  GetOrderListDataParams,
  GetOrderListResult,
  PreOrderResult,
} from '@/types/car'
import { request } from '@/utils/request'
// 加入购物车
// POST
// /member/cart
export const addCartAPI = (data: AddCartDataParams) => {
  return request<AddCartResult>('/member/cart', 'POST', data)
}
// 获取购物车列表
// GET
// /member/cart
export const getCartListAPI = () => {
  return request<AddCartResult[]>('/member/cart', 'GET')
}
// 删除/清空购物车单品
// DELETE
// /member/cart
export const deleteCartAPI = (data: { ids: string[] }) => {
  return request('/member/cart', 'DELETE', data)
}
// 填写订单-获取预付订单
// GET
// /member/order/pre
export const getPreOrderAPI = () => {
  return request<PreOrderResult>('/member/order/pre', 'GET')
}
// 提交订单
// POST
// /member/order
export const createOrderAPI = (data: CreateOrderDataParams) => {
  return request<{ id: string }>('/member/order', 'POST', data)
}
// 填写订单-获取立即购买订单
// GET
// /member/order/pre/now
export const getNowOrderAPI = (data: GetNowOrderDataParams) => {
  return request<GetNowOrderResult>('/member/order/pre/now', 'GET', data)
}
// 获取订单详情
// GET
// /member/order/{id}
export const getOrderDetailAPI = (id: string) => {
  return request<GetOrderDetailResult>(`/member/order/${id}`, 'GET')
}
// 填写订单-获取再次购买订单
// GET
// /member/order/repurchase/{id}
export const getRepurchaseOrderAPI = (id: string) => {
  return request<GetNowOrderResult>(`/member/order/repurchase/${id}`, 'GET')
}
// 模拟支付
// 模拟支付-内测版
// GET
// /pay/mock
export const mockPayAPI = (data: { orderId: string }) => {
  return request('/pay/mock', 'GET', data)
}
// 模拟发货-内测版
// 开发中
// GET
// /member/order/consignment/{id}
export const mockConsignmentAPI = (id: string) => {
  return request(`/member/order/consignment/${id}`, 'GET')
}
// 确认收货
// 开发中
// PUT
// /member/order/{id}/receipt
export const confirmReceiptAPI = (id: string) => {
  return request(`/member/order/${id}/receipt`, 'PUT')
}
// 删除订单
// 开发中
// DELETE
// /member/order
export const deleteOrderAPI = (data: { ids: string[] }) => {
  return request(`/member/order`, 'DELETE', data)
}
// 取消订单
// 开发中
// PUT
// /member/order/{id}/cancel
export const cancelOrderAPI = (id: string, data: { cancelReason: string }) => {
  return request(`/member/order/${id}/cancel`, 'PUT', data)
}
// 获取订单列表
// GET
// /member/order
export const getOrderListAPI = (data: GetOrderListDataParams) => {
  return request<GetOrderListResult>('/member/order', 'GET', data)
}
